<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;

/* @var $this yii\web\View */
/* @var $searchModel app\models\GkyWeAccountSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '微信公众号';
$this->params['breadcrumbs'][] = $this->title;
?>
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/common.js" type="text/javascript"></script>

<div class="gky-we-account-index">

<!--    <div class="col-md-12">      
        <?php
        $form = ActiveForm::begin([
                    'action' => ['index'],
                    'method' => 'get',
                    'options' => ['class' => 'input-group'],
                    'fieldConfig' => [
                        'template' => '<div class="col-lg-12">{input}</div>',
                    ]
                ])
        ?>

        <div class="col-md-7">
            <label style="float: left;margin-top: 5px;">微信号</label>
            <div style="overflow: hidden;">
                <?php
//                $data = app\models\GkyWeAccount::find()->all();
//                echo $form->field($searchModel, 'wename')->widget(Select2::classname(), [
//                    'data' => ArrayHelper::map($data, 'wename', 'wename'),
//                    'options' => ['placeholder' => '请输入内容'],
//                    'pluginOptions' => [
//                        'allowClear' => true
//                    ],
//                ]);
                ?>
                <?php
                $datas = app\models\GkyWeAccount::find()->all();
                if ($datas != null) {
                    foreach ($datas as $item) {
                        $source[] = $item->wename;
                    }
                } else {
                    $source[] = array();
                }
                echo yii\jui\AutoComplete::widget([
                    'model' => $searchModel,
                    'attribute' => 'wename',
                    'options' => ['style' => 'margin-left:10px'],
                    'clientOptions' => [
                        'source' => $source,
                    ],
                ]);
                ?>       
            </div>
        </div>


        <div class="col-md-5 text-center">
            <?= Html::submitButton(' 搜索', ['class' => 'btn btn-primary glyphicon glyphicon-search']) ?> 
             <?= Html::a('添加公众号', ['create'], ['class' => 'btn btn-success']) ?>
        </div>
    </div>-->
    <div class="col-md-12 text-right" style="margin: 15px 0 15px 15px;">
 <?= Html::a('添加公众号', ['create'], ['class' => 'btn btn-success']) ?>
    </div>

    <?=
    GridView::widget([
        'dataProvider' => $dataProvider,
//        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
//            'id',
            'wename',
//            'weno',
//            'wetype',
//            'weoid',
//            'weappid',
//             'wesecret',
//             'weadskey',
            // 'qrcode',
            // 'addtime',
            // 'accesstoken',
            // 'atexpiretime',
            // 'wetoken',
            // 'wemenu:ntext',
            // 'jsapiticket',
            // 'jsapiexpiretime',
            [
                'class' => 'app\common\widgets\ActionColumn',
//                'template' => '{view:view}{update:update}{delete:delete}{change-current:change-current}',
                'template' => '{delete:delete}',
                'buttons' => [
                    // 自定义按钮
                    'view' => function ($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('yii', 'View'),
                            'aria-label' => Yii::t('yii', 'View'),
                            'data-pjax' => '0',
                        ];
                        return Html::a(' 查看 ', $url, $options);
                    },
                            'update' => function ($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('yii', 'Update'),
                            'aria-label' => Yii::t('yii', 'Update'),
                            'data-pjax' => '0',
                        ];
                        return Html::a(' 编辑 ', $url, $options);
                    },
                            'delete' => function ($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('yii', 'Delete'),
                            'aria-label' => Yii::t('yii', 'Delete'),
                            'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                            'data-method' => 'post',
                            'data-pjax' => '0',
                        ];
                        return Html::a(' 删除 ', $url, $options);
                    },
                            'change-current' => function ($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('yii', 'View'),
                            'aria-label' => Yii::t('yii', 'View'),
                            'data-pjax' => '0',
                        ];
                        return Html::a(' 切换 ', $url, $options);
                    },
                        ]
                    ],
                    [
                        'label' => '操作',
                        'format' => 'raw',
                        'value' => function($model) {
                            return Html::Button('菜单', ['onclick' => 'btncaidan()', 'name' => $model->id, 'class' => 'btn btn-default', 'title' => '菜单', 'id' => 'modalButton', 'data-toggle' => 'modal', 'data-target' => '#modal']);
                        }
                            ]
                        ],
                    ]);
                    ?>  
                </div>

                <?php
                yii\bootstrap\Modal::begin([
                    'header' => '菜单编辑器',
                    'id' => 'modal',
                    'size' => 'modal-lg',
                ]);
                ?>   
                <?php
                echo $this->render('popWindow', ['model' => new app\models\GkyWeMenu()]);
                ?>
                <?php yii\bootstrap\Modal::end() ?>
<script type="text/javascript">
    //控制导航菜单的开关
    function btncaidan() {
        if ($("#caidan", window.parent.document))
        {
            $("#caidan", window.parent.document).removeClass("funcmenu_switcher");
            $("#caidan", window.parent.document).addClass("funcmenu_switcher active");
            $("#body", window.parent.document).removeClass("TOS");
            $("#body", window.parent.document).addClass("TOS open-menu");
        }
    }

    $(".close").click(function () {
        $("#caidan", window.parent.document).removeClass("funcmenu_switcher active");
        $("#caidan", window.parent.document).addClass("funcmenu_switcher");
        $("#body", window.parent.document).removeClass("TOS open-menu");
        $("#body", window.parent.document).addClass("TOS");
    });
</script>



